// 转换经纬度

export default {
  change (position, mode) {
    let str = ''
    if (mode == 'toTime') { // 转换成时分秒
      const arr1 = `${position}`.split('.')
      const d = arr1[0] ? arr1[0] : 0
      let tp = `0.${arr1[1] ? arr1[1] : 0}`
      tp = String(tp * 60) //这里进行了强制类型转换
      const arr2 = tp.split('.')
      const f = arr2[0] ? arr2[0] : 0
      tp = `0.${arr2[1] ? arr2[1] : 0}`
      tp = tp * 60
      const m = tp.toFixed(4)
      str = d + '°' + f + '\'' + m + '"'
    } else if (mode == 'toDeg') { // 转换成浮点数
      const arr1 = position.split('"')[0].split('°')
      const d = arr1[0]
      const arr2 = arr1[1].split('\'')
      let f = arr2[0] || 0
      const m = arr2[1] || 0
      f = parseFloat(f) + parseFloat(m / 60)
      str = parseFloat(f / 60) + parseFloat(d)
    }
    return str
  }
}
